﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using MM.Common.DBBase;
using System.ComponentModel;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraGrid.Views.Base;
using System.Drawing;
using System.Drawing.Drawing2D;
using MM.Common.Base;
using DevExpress.Internal;
using MM.Common.Setup;
using System.Windows.Forms;
using MM.Commmon.UI;

namespace MM.Common.Support
{
    public partial class FrmCommonDataSetup : FrmSetupWithSelect
    {
        private DataTable dtDataType;

        public FrmCommonDataSetup()
        {
            this.InitializeComponent();
        }

        protected void DispInfo()
        {
            DataParamCol parm = new DataParamCol(new DataParam[] { new InputDataParam("data_type", base.mainCode.ToString()) });
            base.RetrieveData(parm);
            base.dtSetup.Columns["DATA_TYPE"].DefaultValue = base.mainCode;
            base.dtSetup.Columns["USED_FLAG"].DefaultValue = "Y";
        }

        protected override bool selectFresh()
        {
            if (this.dtDataType == null)
            {
                this.dtDataType = new DataTable();
                SystemInfo.DbData.Retrieve("SELECT DATA_TYPE ,DATA_VALUE FROM MXHLY_DIC_COMMON_DATA WHERE DATA_CODE = '*' ORDER BY DATA_TYPE", ref this.dtDataType);
            }
            int[] numArray = new int[2];
            numArray[1] = 100;
            FrmSelectFromGrid grid = new FrmSelectFromGrid(this.dtDataType, new string[] { "类型", "类型名称" }, numArray, "数据类型选择");
            if (grid.ShowDialog(this) != System.Windows.Forms.DialogResult.Cancel)
            {
                int choiceRow = grid.ChoiceRow;
                base.mainCode = this.dtDataType.Rows[choiceRow]["DATA_TYPE"];
                this.Text = "公共数据设置 --- " + this.dtDataType.Rows[choiceRow]["DATA_VALUE"].ToString();
                grid.Dispose();
                this.DispInfo();
                return true;
            }
            base.mainCode = null;
            return false;
        }


        private void FrmSysConfigSetup_Load(object sender, EventArgs e)
        {
            base.gvSetup = this.gvData;
            this.gcDataValue.Tag = "ON";
            string selsql = "SELECT DATA_TYPE ,DATA_CODE ,DATA_VALUE ,INPUTCODE1 ,INPUTCODE2 ,USED_FLAG ,CASE_CODE FROM MXHLY_DIC_COMMON_DATA \r\n   WHERE DATA_TYPE = :data_type AND DATA_CODE <> '*'  \r\n   ORDER BY DATA_CODE ASC ";
            base.setSql(selsql, "MXHLY_DIC_COMMON_DATA", new string[] { "DATA_TYPE", "DATA_CODE" }, null, "DATA_CODE", "");
            base.InputColumn = "gcDataValue";
            base.ZoomWin();
            this.selectFresh();
        }
    }
}
